#include "stdafx.h"
#include "Station.h"


Station::Station(void)
{
	_name.SetParent(this);
}


Station::~Station(void)
{
}
BEGIN_MESSAGE_MAP(Station, Graphic)
	ON_WM_PAINT()
END_MESSAGE_MAP()


void Station::initPos(CPoint& pt1, CPoint& pt2)
{
	CRect rect = CRect(pt1, pt2);
	rect.NormalizeRect();

	setupWindow(rect);
	setupNamePos();
}


void Station::OnPaint()
{
	CPaintDC dc(this); 

	CRect clientRect;
	GetClientRect(&clientRect);
	dc.SelectStockObject(WHITE_PEN);
	dc.SelectStockObject(NULL_BRUSH);

	dc.Rectangle(clientRect);
}


void Station::Serialize(CArchive& ar)
{
	Graphic::Serialize(ar);
	_name.Serialize(ar);

	if (ar.IsStoring())
	{	// storing code
	}
	else
	{	// loading code
		setupNamePos();
	}
}


void Station::setupNamePos(void)
{
	CRect clientRect;
	GetClientRect(&clientRect);

	CSize  nameSize = getTextSize(_name._text, &_name._font);
	CPoint topLeft((clientRect.right - nameSize.cx) / 2, (clientRect.bottom - nameSize.cy) / 2);
	CRect  nameRect(topLeft, CPoint(topLeft.x + nameSize.cx, topLeft.y + nameSize.cy));

	_name.MoveWindow(nameRect);
}
